from django.shortcuts import render,redirect
from django.http import HttpResponse,JsonResponse
import json
from index import models
from utils.msg import info
# Create your views here.


# import socket
# s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# hostname = socket.gethostname()  # 获取电脑名称  gethostbyname 参数为一个域名，返回一个指向hostent 的指针
# ip=socket.gethostbyname(hostname) # 获取电脑ip
# print("我的主机名字为{}，主机ip为{}".format(hostname,ip))

def carousel(request):
    data=models.Carousel.objects.all()
    li=[]
    for index in range(len(data)):
        obj={"img_id":data[index].id,"img_src":data[index].img_src}
        li.append(obj)
    print(li)
    data=json.dumps(li)
    response = HttpResponse(data)
    response["Access-Control-Allow-Origin"] = "*"
    return response
